http_client: Fully download archives before extracting them - #62653
Open
morgankrey wants to merge 2 commits into
Open
http_client: Fully download archives before extracting them#62653morgankrey wants to merge 2 commits into
morgankrey wants to merge 2 commits into
Conversation
Archives without a SHA-256 digest were extracted directly from the network stream, so an interrupted download surfaced as an opaque archive-extraction error, indistinguishable from a corrupt asset. Buffer every archive to a temporary file first, matching what the digest-verifying path already did, and only then extract.
Connect and session-creation failures were flattened with
`to_string`, which keeps only the outermost anyhow context and hides
the root cause (e.g. a truncated download) from the panel, the log,
and telemetry. Format with `{:#}` to keep the chain, log the debug
form, and downcast session errors to LoadError so typed variants
survive.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Installing an external agent (or a language server) from an archive that ships without a SHA-256 checksum used a fragile code path: Zed unpacked the archive directly from the network stream, without ever saving the complete file to disk. If the connection dropped partway through the download, the unpacker saw the data stop mid-file and failed with an archive-extraction error that looks identical to a corrupt package. Users hit this with the Cursor agent, whose ACP registry entry has no checksum and whose package is a 71 MB download: any network hiccup produced a confusing "Failed to Install" error with no hint that the download was the problem.
This change makes both paths behave the same way: every archive is now fully downloaded to a temporary file first, and only then unpacked. The checksum verification still runs when a checksum is available, exactly as before; when none is available it is simply skipped. This removes no protection that exists today, since the streaming path performed no verification either. A failed download now reports a download error ("saving archive contents into the temporary file for ") instead of a misleading extraction error.
The second commit fixes the reason these failures were undiagnosable: agent connect and session-creation errors were flattened with
to_string, which keeps only the outermost message of an error chain. The underlying cause (invalid gzip, unexpected end of file, connection reset) never reached the panel, the log, or telemetry. Errors are now formatted with the full context chain for display, logged with their debug representation, and session errors are downcast toLoadErrorfirst so typed variants keep their specific handling.The trade-offs are small: the archive briefly occupies temporary disk space, and installation finishes slightly later because unpacking waits for the download to complete.
Intentionally out of scope, as follow-ups: deduplicating concurrent installs of the same version, and cleaning up staging directories left behind by cancelled installs.
Testing:
cargo nextest run -p http_client --features github-download: 8 tests, all passing.cargo nextest run -p agent_ui load_error: 4 tests, all passing.cargo fmt --checkandscript/clippypass.Release Notes: